<template>
	<view class="rob-order">
		<div v-if="orderList.length" class="order-card-list">
			<cuCard
				v-for="order in orderList"
				:key="order.id"
				:type="order.type"
				:weight="order.weight"
				:status="order.status"
				:id="order.id"
				:address="order.address"
				:remark="order.remark"
				:createTime="order.createTime"
			/>
			<p class="loading-text">
				{{loadingType === 0 ? loadingStatus.conuentDown: loadingType === 1 ? loadingStatus.contentFresh : loadingStatus.contentNoMore }}
			</p>
		</div>
		<div v-else class="empty-row">
			<Empty />
		</div>
	</view>
</template>

<script>
import cuCard from '@/components/cu-card/cu-card.vue';
import Empty from '@/components/empty/empty.vue';
export default {
	components: {
		cuCard,
		Empty
	},
	data() {
		return {
			orderList: [
				{ id: '0', createTime: '1594969434274', type: 1, weight: 2, address: '北京市海淀区学院路街道30号', remark: '东西比较沉，一个人可能拿不到', status: 1 },
				{ id: '1', createTime: '1594969434274', type: 1, weight: 2, address: '北京市海淀区学院路街道30号', remark: '东西比较沉，一个人可能拿不到', status: 1 },
				{ id: '2', createTime: '1594969434274', type: 1, weight: 2, address: '北京市海淀区学院路街道30号', remark: '东西比较沉，一个人可能拿不到', status: 1 },
				{ id: '3', createTime: '1594969434274', type: 1, weight: 2, address: '北京市海淀区学院路街道30号', remark: '东西比较沉，一个人可能拿不到', status: 1 },
				{ id: '4', createTime: '1594969434274', type: 1, weight: 2, address: '北京市海淀区学院路街道30号', remark: '东西比较沉，一个人可能拿不到', status: 1 }
			],
			pagination:{
				current: 1,
				pageSize: 10
			},
			loadingStatus: {
				conuentDown: '上拉显示更多',
				contentFresh: '正在加载···',
				contentNoMore: '没有更多数据了'
			},
			loadingType: 0,
			error: false,
			loading: false,
			loadingText: '上拉加载更多',
			total: 0
		};
	},
	onReady() {
		this.getOrderList()
	},
	methods: {
		// 请求订单
		getOrderList() {
			uni.showLoading({
				title: '正在搜素附近订单'
			})
			this.$request.order.queryRobOrderList()
				.then(res =>{
					uni.hideLoading()
					if(res.status === 200) {
						this.orderList = res.data.list
						this.pagination.current = this.pagination.current + 1
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})
				.catch(() =>{
					uni.hideLoading()
					uni.showToast({
						title: '服务器出错了',
						icon: 'none'
					})
				})
		},
		// 刷新
		handleRefresher() {
			console.log(1)
		},
		// 触发底部
		handleLower() {
			this.getOrderList()
		},
		// 抢单
		handleActive(id) {
			this.$request.order
				.grabOrder({
					orderId: id
				})
				.then(res => {
					if (res.status === 200) {
						uni.showToast({
							title: '抢单成功',
							icon: 'success'
						});
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.rob-order {
	min-height: 100vh;
	padding: 20rpx;
	background: $cu-bg;
}
</style>
